package com.itheima.pattern.t3_prototype.demo4;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * 原型模式-深克隆
 */
public class TestDemo {

    public static void main(String[] args) throws Exception {
        // 创建原型对象
        Citation citation = new Citation();
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);

        // 创建对象输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("F:\\a.txt"));
        // 写对象
        oos.writeObject(citation);
        // 释放资源
        oos.close();

        // 创建对象输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("F:\\a.txt"));
        // 读对象
        Citation citation1 = (Citation) ois.readObject();
        // 释放资源
        ois.close();

        Student student1 = citation1.getStudent();
        student1.setName("李四");
        citation.show();
        citation1.show();
    }
}
